﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MyOrders.aspx.cs" Inherits="Skyworth.CRM.Web.Orders.MyOrders" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>订单查询</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=7" />
    <%--[if IE]>
     <link href="../themes/css/ieHack.css" rel="stylesheet" type="text/css" />
    <![endif]--%>
    <link href="../themes/default/style.css" rel="stylesheet" type="text/css" />
    <link href="../themes/css/core.css" rel="stylesheet" type="text/css" />
    <link href="../themes/css/pages.css" rel="stylesheet" type="text/css" />
    <link href="../javascripts/My97DatePicker/skin/WdatePicker.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="../themes/css/jquery.cluetip.css" type="text/css" />
    <link href="../themes/css/Messagebox.css" rel="stylesheet" type="text/css" />

    <script src="../javascripts/jquery-1.4.4.min.js" type="text/javascript"></script>
    <script src="../javascripts/json2.js" type="text/javascript"></script>
    <script src="../javascripts/dwz.core.js" type="text/javascript"></script>
    <script src="../javascripts/jquery.cluetip.min.js" type="text/javascript"></script>
    <script src="../javascripts/MessageBox.js" type="text/javascript"></script>

    <script src="../javascripts/dwz.pagination.js" type="text/javascript"></script>

    <script src="../javascripts/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
    <style type="text/css">
        .content
        {
            overflow: auto;
            border: solid 1px #CCC;
            line-height: 21px;
            background: #FFF;
            padding: 2px;
        }
        .linkDisabled
        {
        	color:Gray;
        }
    </style>
    <script type="text/javascript">
        var addWindow;
        var custId =<%=CustId %>;
        var userType=<%=UserType %>;
        //下一页
        function dwzPageBreak(args) {
            $("#pageNum").val(args["pageNum"]);
            $(" #selectedId").val("");
            GetOrders();
        }

        //设置翻页    
        function SetPager(pagerId, pageMsgId, numPerPage, currentPage, totalRecords, totalPages) {
            $(pageMsgId).text("  共【" + totalRecords + "】条，【" + totalPages + "】页");

            $(pagerId).each(function() {
                var $this = $(this);
                $this.pagination({
                    targetType: $this.attr("targetType"),
                    totalCount: totalRecords,
                    numPerPage: numPerPage,
                    pageNumShown: $(this).attr("pageNumShown"),
                    currentPage: currentPage
                });
            });
        }

        function DeleteOrder(orderId) {
            var paramList = '{"orderId":"' + orderId + '"}';
            $.ajax({
                type: "POST",
                url: "MyOrders.aspx/DeleteOrder",
                contentType: "application/json; charset=utf-8",
                data: paramList,
                dataType: "json",
                success: function(data) {
                    if (data.d) {
                        GetOrders();
                    }
                },
                error: function(msg) { $.Messager.Alert({ Title: '系统消息', Message: "发生异常，删除订单失败！", Icon: IconType.Warning }); }
            })
        }
        
        function SubmitOrders(orderId,status){
           var paramList = '{"orderId":"' + orderId + '","status":"'+status+'"}';
            $.ajax({
                type: "POST",
                url: "MyOrders.aspx/SubmitOrder",
                contentType: "application/json; charset=utf-8",
                data: paramList,
                dataType: "json",
                success: function(data) {
                    if (data.d) {
                        GetOrders();
                    }
                },
                error: function(msg) { $.Messager.Alert({ Title: '系统消息', Message: "发生异常，提交订单失败！", Icon: IconType.Warning }); }
            })
        
        }

        function GetOrders() {
            var paramList = new Object();
            paramList.status = $("#ddlStatus").val();
            paramList.orderCode = $("#txtCode").val();
            paramList.startDate = $("#txtStartDate").val();
            paramList.endDate = $("#txtEndDate").val();
            paramList.orderField = $("#orderField").val();
            paramList.orderValue = $("#orderValue").val();
            paramList.pageIndex = $("#pageNum").val();
            paramList.pagePerSize = $("#numPerPageSelect").val();
            paramList.custId=custId;
            paramList.userType=userType;
            $.ajax({
                type: "POST",
                url: "MyOrders.aspx/GetOrders",
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify(paramList),
                dataType: "json",
                success: function(data) {
                    var dataTable = jQuery.parseJSON(data.d);
                    //填充数据
                    $("#ordersTable tbody").empty();
                    var lists = "";
                    $.each(dataTable.rows, function(i, item) {
                        var orderDate =eval("new "+item.FUpdateDate.replace(/\//g,""));
                        lists = lists + "<tr rel='" + item.FitemId + "' status='"+item.Fstatus+"'>" +
                        "<td width='100'><a href='javascript:void(0)' rel='OrderDetails.aspx?orderId="+item.FitemId+"'>" + item.Fnumber + "</a></td>" +
                        "<td ><a href='javascript:void(0)' rel='OrderProcess.aspx?orderId="+item.FitemId+"'>" + item.Ftitle + "</a></td>" +
                        "<td >" + item.ContactName + "</td>" +
                        "<td >" + item.FDreeName + "</td>" +
                        "<td >" + item.stockName + "</td>" +
                        "<td >" + item.Fqty + "</td>" +
                        "<td >" + item.Fvolume + "</td>" +
                        "<td >" + item.Fprice + "</td>" +
                        "<td >" + item.FtaxPrice + "</td>" +
                        "<td width='100'>" + orderDate.getFullYear() + "-" + (orderDate.getMonth() + 1) + "-" + orderDate.getDate() + "</td>" +
                        "<td >" + item.StatusName + "</td>" +
                        "</tr>";
                    })
                    $(lists).appendTo($("#ordersTable tbody"));

                    //绑定事件
                    $("#ordersTable tr:nth-child(even)").attr('class', "trbg");
                    $("#ordersTable tbody tr").click(function() {
                        $(" #selectedId").val($(this).attr("rel"));
                        var status=$(this).attr("status");
                        if(status==0 || status==5){
                           $("#btnDelete").removeClass("linkDisabled").removeAttr("disabled");
                           $("#btnUpdate").removeClass("linkDisabled").removeAttr("disabled");
                           $("#btnSubmit").removeClass("linkDisabled").removeAttr("disabled");
                        }
                        else{
                            $("#btnDelete").addClass("linkDisabled").attr("disabled","disabled");
                            $("#btnUpdate").addClass("linkDisabled").attr("disabled","disabled");
                            $("#btnSubmit").addClass("linkDisabled").attr("disabled","disabled");
                        }
                        
                        $(this).addClass("selected");
                        $(this).siblings("tr").removeClass("selected");
                    }).hover(function() {
                        $(this).addClass('hover');
                    }, function() {
                        $(this).removeClass('hover');
                    })
                    $("#ordersTable tbody tr").each(function(){
                        $(this).find("td").eq(0).find("a").cluetip({ cluetipClass: 'jtip', width: '810px', sticky: true, activation: 'click', closePosition: 'title', arrows: true, closeText: '<img src="../themes/images/cancel.png" alt="【关闭】" />' })
                        $(this).find("td").eq(1).find("a").cluetip({ cluetipClass: 'jtip', width: '465px', sticky: true, activation: 'click', closePosition: 'title', arrows: true, closeText: '<img src="../themes/images/cancel.png" alt="【关闭】" />' ,ajaxCache:false });
                    });
                    
                    SetPager("#policyPanel div.pagination", "#policyPanel #pageMsg", $("#policyPanel #numPerPageSelect").val(), $("#policyPanel #pageNum").val(), dataTable.totalRecords, dataTable.totalPages);

                },
                error: function(msg) { $.Messager.Alert({ Title: '系统消息', Message: "发生异常，获取订单数据失败！", Icon: IconType.Warning }); },
                beforeSend: function(){$("#LoadingPanel").fadeIn("slow");},
                complete: function(){$("#LoadingPanel").fadeOut("fast");}
            })

        }

        $(document).ready(function() {
            
            GetOrders();

            $("#btnSearch").click(function() {
                GetOrders();
                return false;
            })

            $("div.panelBar li").hover(function() { $(this).addClass("hover"); },
                                     function() { $(this).removeClass("hover"); })

            $("#policyPanel #numPerPageSelect").change(function() {
                $("#policyPanel #pageNum").val(1);
                $("#policyPanel #selectedId").val("");
                GetOrders();
            })

            // init styles
            $("input[type=text]").addClass("textInput").focusClass("focus");
            $("div.button").hover(function() { $(this).addClass("buttonHover"); },
                                 function() { $(this).removeClass("buttonHover"); });
            $("div.buttonActive").hover(function() { $(this).addClass("buttonActiveHover"); },
                                function() { $(this).removeClass("buttonActiveHover"); }) 
                                
            $("#btnDelete").click(function() {
                if ($(this).attr("disabled") != "disabled") {
                    var orderId = $("#ordersTable tbody tr.selected:eq(0)").attr("rel");
                    if (orderId && parseInt(orderId) > 0 ) {
                        $.Messager.Confirm({ Title: '系统警告', Message: '你确定要删除该订单吗？', Icon: IconType.Question,
                            Oncallback: function(IsYes, Id) {
                                if (IsYes) { DeleteOrder(orderId); }
                            }
                        })
                    }
                    else {
                        $.Messager.Alert({ Title: '系统消息', Message: "请选择要删除的订单！", Icon: IconType.Warning });
                    }
                }
                 return false;
            })

            $("#btnUpdate").click(function() {
                if ($(this).attr("disabled") != "disabled") {
                    var orderId = $("#ordersTable tbody tr.selected:eq(0)").attr("rel");
                    var orderCode=$("#ordersTable tbody tr.selected:eq(0)").find("td").eq(0).text();
                    var url="Orders/AddOrder.aspx?Type=update&Id="+orderId;
                    if(userType==1)
                    {
                        url="Orders/EmpAddOrder.aspx?Type=update&Id="+orderId;
                    }
                    if (orderId && parseInt(orderId) > 0 ) {
                        parent.navTab.openTab("EditOrder"+orderId,url , { title: '修改订单：'+orderCode, isIframe: true });
                    }
                    else {
                        $.Messager.Alert({ Title: '系统消息', Message: "请选择要修改的订单！", Icon: IconType.Warning });
                    }
                }
                return false;
            })

            $("#btnAdd").click(function() {
                if ($(this).attr("disabled") != "disabled") {
                    var url="Orders/AddOrder.aspx?Type=add";
                    if(userType==1)
                    {
                        url="Orders/EmpAddOrder.aspx?Type=add";
                    }
                   parent.navTab.openTab("NewOrder", url, { title: '新增订单', isIframe: true });
                }
                return false;
            })

            $("#ordersTable thead th[colName]").click(function() {
                $("#policyPanel #orderField").val($(this).attr("colName"));
                if ($(this).hasClass("headerSortUp")) {
                    $("#policyPanel #orderValue").val("desc");
                    $(this).removeClass("headerSortUp").addClass("headerSortDown");
                }
                else {
                    $("#policyPanel #orderValue").val("asc");
                    $(this).removeClass("headerSortDown").addClass("headerSortUp");
                }
                $(this).siblings("th").removeClass("headerSortUp").removeClass("headerSortDown");
                $("#policyPanel #pageNum").val(1);
                GetOrders();
            })
            
             $("#btnSubmit").click(function() {
                if ($(this).attr("disabled") != "disabled") {
                    var orderId = $("#ordersTable tbody tr.selected:eq(0)").attr("rel");
                    var orderCode=$("#ordersTable tbody tr.selected:eq(0)").find("td").eq(0).text();
                    var status=$("#ordersTable tbody tr.selected:eq(0)").attr("status");
                    if (orderId && parseInt(orderId) > 0 ) {
                        $.Messager.Confirm({ Title: '系统警告', Message: '提交订单后，在未被处理之前，你将不能操作改订单。你确定要提交该订单吗？', Icon: IconType.Question,
                            Oncallback: function(IsYes, Id) {
                                if (IsYes) { SubmitOrders(orderId,status); }
                            }
                        })
                    }
                    else {
                        $.Messager.Alert({ Title: '系统消息', Message: "请选择要提交的订单！", Icon: IconType.Warning });
                    }
                }
                return false;
            })

        })
    
    </script>
</head>
<body style="background-color: #FFF; overflow:visible">
    <form id="form1" runat="server">
    <div>
        <div style="margin: 2px;">
            <div class="panel" id="policyPanel">
                <div class="panelHeader">
                    <div class="panelHeaderContent">
                        <h1>
                            我的订单</h1>
                    </div>
                </div>
                <div class="panelContent">
                    <div class="content">
                        <table width="100%" id="policy">
                            <tr>
                                <td>
                                    <div class="searchBar" style="padding: 4px 5px;">
                                        <ul>                                           
                                            <li style="float: left;"><span>订单编号：</span>
                                                <asp:TextBox ID="txtCode" runat="server"></asp:TextBox>
                                            </li>
                                            <li style="float: left; padding-left: 10px;"><span>下单日期： 从</span>
                                                <asp:TextBox ID="txtStartDate" runat="server" 
                                                    onClick="WdatePicker({skin:'ext',maxDate:'#F{$dp.$D(\'txtEndDate\')}'})" 
                                                    ReadOnly="True"></asp:TextBox>
                                            </li>
                                             <li style="float: left; padding-left: 10px;"><span>至</span>
                                                <asp:TextBox ID="txtEndDate" runat="server" 
                                                     onClick="WdatePicker({skin:'ext',minDate:'#F{$dp.$D(\'txtStartDate\')}'})" 
                                                     ReadOnly="True"></asp:TextBox>
                                            </li>
                                            <li style="float: left;padding-left: 10px;"><span>订单状态：</span>
                                                <select id="ddlStatus">
                                                    <option value="-1">全部</option>
                                                    <option value="0" >起草阶段</option>
                                                    <option value="1">待审批</option>
                                                    <option value="2">已通过</option>
                                                    <option value="3">处理中</option>
                                                    <option value="4">被拒绝</option>
                                                    <option value="5">被驳回</option>
                                                </select>
                                            </li> 
                                            <li style="float: left; padding-left: 20px">
                                                <div class="buttonActive">
                                                    <div class="buttonContent">
                                                        <asp:Button ID="btnSearch" runat="server" Text="查询" ToolTip="查询我的订单信息" CssClass="serverButton" />
                                                    </div>
                                                </div>
                                            </li>
                                            <li style="clear: both" ></li>
                                        </ul>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <div>
                                        <div class="panelBar">
                                            <ul class="toolBar">
                                                <li class="">
                                                    <asp:LinkButton ID="btnAdd" runat="server" CssClass="add"><span>新增订单</span> </asp:LinkButton></li>
                                                <li class="line">line</li>
                                                <li class="">
                                                    <asp:LinkButton ID="btnUpdate" runat="server" CssClass="edit linkDisabled" ><span>修改订单</span> </asp:LinkButton></li>
                                                <li class="line">line</li>
                                                <li class="">
                                                    <asp:LinkButton ID="btnDelete" runat="server" CssClass="delete linkDisabled"  ><span>删除订单</span> </asp:LinkButton></li>
                                                <li class="line">line</li>
                                                 <li class="">
                                                    <asp:LinkButton ID="btnSubmit" runat="server" CssClass="icon linkDisabled" ><span>提交订单</span> </asp:LinkButton></li>
                                                <li class="">
                                                    <asp:Button ID="btnhidDelete" runat="server" Text="" Style="display: none;" />
                                                    <input type="hidden" style="display: none;" id="selectedId" runat="server" />
                                                </li>
                                            </ul>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <div style="_margin-top: -2px;">                                        
                                        <div class="tableList">
                                            <table width="100%"  class="list" id="ordersTable" >
                                                <thead>
                                                    <tr>
                                                        <th width="100" valign="middle" style="cursor: pointer;" colname="T_Order.Fnumber">
                                                            <span style="float: left">订单编号</span> <span style="float: right;" class="sortIcon">
                                                            </span>
                                                        </th>
                                                        <th valign="middle" style="cursor: pointer;" colname="Ftitle">
                                                            <span style="float: left">订单名称</span> <span style="float: right;" class="sortIcon">
                                                            </span>
                                                        </th>
                                                        <th valign="middle" style="cursor: pointer;" colname="FcontactID">
                                                            <span style="float: left">联系人</span> <span style="float: right;" class="sortIcon">
                                                            </span>
                                                        </th>
                                                        <th valign="middle" style="cursor: pointer;" colname="FCusDreeID">
                                                            <span style="float: left">收货地址</span> <span style="float: right;" class="sortIcon">
                                                            </span>
                                                        </th>
                                                        <th valign="middle" style="cursor: pointer;" colname="FstockID">
                                                            <span style="float: left">收货仓库</span> <span style="float: right;" class="sortIcon">
                                                            </span>
                                                        </th>
                                                        <th valign="middle" style="cursor: pointer;" colname="Fqty">
                                                            <span style="float: left">总数量</span> <span style="float: right;" class="sortIcon">
                                                            </span>
                                                        </th>
                                                        <th valign="middle" style="cursor: pointer;" colname="Fvolume">
                                                            <span style="float: left">总体积</span> <span style="float: right;" class="sortIcon">
                                                            </span>
                                                        </th>
                                                        <th valign="middle" style="cursor: pointer;" colname="Fprice">
                                                            <span style="float: left">不含税金额</span> <span style="float: right;" class="sortIcon">
                                                            </span>
                                                        </th>
                                                        <th valign="middle" style="cursor: pointer;" colname="FtaxPrice">
                                                            <span style="float: left">含税金额</span> <span style="float: right;" class="sortIcon">
                                                            </span>
                                                        </th>
                                                        <th valign="middle" style="cursor: pointer;" colname="FUpdateDate" class="headerSortDown">
                                                            <span style="float: left">下单日期</span> <span style="float: right;" class="sortIcon">
                                                            </span>
                                                        </th>
                                                        <th  class="left" >
                                                            <div class="gridCol" title="订单状态">订单状态</div>
                                                        </th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                </tbody>
                                          </table>
                                        </div>
                                        <div class="panelBar">
                                            <div class="pages">
                                                <span>每页显示</span>
                                                <div style="float: left">
                                                    <select id="numPerPageSelect" runat="server">
                                                        <option>1</option>
                                                        <option>2</option>
                                                        <option>15</option>
                                                        <option>20</option>
                                                        <option>25</option>
                                                        <option selected="selected">30</option>
                                                        <option>35</option>
                                                        <option>40</option>
                                                        <option>45</option>
                                                        <option>50</option>
                                                    </select>
                                                </div>
                                                <span id="pageMsg"></span>
                                            </div>
                                            <div class="pagination" targettype="navTab" pagenumshown="3">
                                            </div>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <input type="hidden" id="pageNum" name="pageNum" value="1" runat="server" />
                                    <input type="hidden" id="orderField" name="orderField" value="FUpdateDate" runat="server" />
                                    <input type="hidden" id="orderValue" name="orderValue" value="desc" runat="server" />
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
                <div class="panelFooter">
                    <div class="panelFooterContent">
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div id="LoadingPanel" style="display: none;">
        <div id='background' class='background'>
        </div>
        <div id='progressBar' class='progressBar'>
            数据加载中，请稍等...</div>
    </div>
    </form>
</body>
</html>